// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

#include "stdafx.h"

using namespace Common;
using namespace Hosting2;
using namespace Api;
using namespace std;

BOOL APIENTRY DllMain(
    HMODULE module,
    DWORD reason,
    LPVOID reserved)
{
    UNREFERENCED_PARAMETER(module);
    UNREFERENCED_PARAMETER(reserved);

    switch (reason)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

//
// WARNING: 
//
// The signature below MUST exactly match (including the parameter names)
// with the signature generated by MIDL in the FabricContainerActivatorService_.h file. 
// Otherwise the linker does not apply the extern "C" specifier and exports 
// this function as C++ name mangled function instead of C style function.
// 
/* [entry] */ HRESULT CreateFabricContainerActivatorServiceAgent(
    /* [in] */ __RPC__in REFIID riid,
    /* [retval][out] */ __RPC__deref_out_opt void **fabricContainerActivatorServiceAgent)
{
    if (riid != IID_IFabricContainerActivatorServiceAgent)
    { 
        return ComUtility::OnPublicApiReturn(E_NOINTERFACE);
    }

    shared_ptr<ContainerActivatorServiceAgent> activatorServiceAgentSPtr;
    auto error = ContainerActivatorServiceAgent::Create(activatorServiceAgentSPtr);
    if (!error.IsSuccess())
    {
        return ComUtility::OnPublicApiReturn(error.ToHResult());
    }

    auto activatorServiceAgentPtr =
        RootedObjectPointer<IContainerActivatorServiceAgent>(
            activatorServiceAgentSPtr.get(),
            activatorServiceAgentSPtr->CreateComponentRoot());

    auto activationManagerCPtr = WrapperFactory::create_com_wrapper(activatorServiceAgentPtr);

    *fabricContainerActivatorServiceAgent = activationManagerCPtr.DetachNoRelease();

    return ComUtility::OnPublicApiReturn(S_OK);
}

/* [entry] */ HRESULT LoadHostingSettings(
    /* [retval][out] */ __RPC__deref_out_opt void **fabricHostingSettings)
{
    auto comResult = make_com<ComHostingSettingsResult>();

    *fabricHostingSettings = comResult.DetachNoRelease();

    return ComUtility::OnPublicApiReturn(S_OK);
}

